package com.wc.AlgoOJ_train.train1.c1.A117;

import java.util.HashMap;
import java.util.Locale;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/12/30 11:38
 * @description GTQ数
 * http://43.138.190.70:8888/p/A117
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i <= 9; i++) {
            map.put(String.valueOf(i).charAt(0), i);
        }
        for (int i = 0; i < 26; i++) {
            map.put((char) ('A' + i), i + 10);
        }
        while (sc.hasNextInt()) {
            int num = sc.nextInt();
            if (num == 0) {
                break;
            }
            int a = num;
            int sum = 0;
            String s16 = Integer.toString(a, 16).toUpperCase(Locale.ROOT);
            String s12 = Integer.toString(a, 12).toUpperCase(Locale.ROOT);
            while (a != 0) {
                sum += a % 10;
                a /= 10;
            }
            int sum16 = 0;
            for (char ch : s16.toCharArray()) {
                sum16 += map.get(ch);
            }
            if (sum != sum16) {
                System.out.println(num + " is not a GTQ Number.");
                continue;
            }
            int sum12 = 0;
            for (char ch : s12.toCharArray()) {
                sum12 += map.get(ch);
            }
            if (sum12 == sum) {
                System.out.println(num + " is a GTQ Number.");
            }else {
                System.out.println(num + " is not a GTQ Number.");
            }
        }
    }
}
